<!--采购计划-->
<template>
  <div class="app-container">
    <el-form :model="selectForm" ref="selectForm" :inline="true">
      <el-form-item label="计划单号">
        <el-input v-model="selectForm.planCode" placeholder="请输入计划单号" clearable size="small"
                  @keyup.enter.native="getList"/>
      </el-form-item>
      <el-form-item label="创建日期">
        <el-date-picker @keyup.enter.native="getList" v-model="date" size="small" value-format="yyyy-MM-dd"
                        type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
                        @change="dateSelect"></el-date-picker>
      </el-form-item>
<!--      <el-form-item label="审核状态">-->
<!--        <el-select @change="getList" v-model="selectForm.verifyStatus" placeholder="审核状态" clearable size="small">-->
<!--          <el-option-->
<!--            v-for="item in [{value:1,label:'进行中'},{value:2,label:'已结束'},{value:3,label:'未提交'}]"-->
<!--            :key="item.value" :label="item.label" :value="item.value"/>-->
<!--        </el-select>-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-checkbox v-model="myReview" @change="getList">我审核的</el-checkbox>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" v-hasPermi="['purchaseGL:cgju:search']"
                   @click="getList">搜索
        </el-button>
        <el-button type="success" icon="el-icon-plus" size="mini" v-hasPermi="['purchaseGL:cgju:add']" @click="add"
                   v-if="!myReview">添加
        </el-button>
        <el-button type="warning" icon="el-icon-download" size="mini" @click="exportList" v-hasPermi="['purchaseGL:cgju:export']">导出</el-button>
        <el-upload
          style="float: right;margin-left:10px;"
          :headers="headers"
          accept=".xlsx, .xls"
          :show-file-list="false"
          :action="baseUrl()+'/device/procurePlan/excel'"
          :on-success="toLeadSuccess"
          v-hasPermi="['purchaseGL:cgju:toLead']"
        >
<!--          <el-button size="mini" type="info" icon="el-icon-upload">导入</el-button>-->
        </el-upload>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="list.rows" border>
      <el-table-column align="center" type="index" label="序号" width="55"/>
      <el-table-column align="center" label="计划单号" property="planCode" width="150">
        <template slot-scope="scope" style="text-align: center">
          <el-button size="mini" type="text" @click="details(scope.row)"  v-hasPermi="['purchaseGL:cgju:details']">
            {{scope.row.planCode}}
          </el-button>
        </template>
      </el-table-column>
      <el-table-column align="center" label="标题" property="title" :show-overflow-tooltip="true" width="150"></el-table-column>
      <el-table-column align="center" label="采购类型" property="procureType" width="100">
        <template slot-scope="scope">
          <template v-if="scope.row.procureType==1">设备</template>
<!--          <template v-if="scope.row.procureType==2">备件</template>-->
        </template>
      </el-table-column>
<!--      <el-table-column align="center" label="采购数量" property="anticipatedTotalNumber" width="100"/>-->
            <el-table-column align="center" label="采购计划类型" property="purchasePlanType" width="100">
              <template slot-scope="scope" style="text-align: center">
                <template v-if="scope.row.purchasePlanType==1">临时</template>
                <template v-if="scope.row.purchasePlanType==2">月度</template>
                <template v-if="scope.row.purchasePlanType==3">年度</template>
              </template>
            </el-table-column>
<!--      <el-table-column align="center" label="计划采购金额" property="anticipatedTotalPrice"/>-->
<!--      <el-table-column align="center" label="采购周期类型" property="procureCircleType">-->
<!--        <template slot-scope="scope" style="text-align: center">-->
<!--          <template v-if="scope.row.procureCircleType==1">年</template>-->
<!--          <template v-if="scope.row.procureCircleType==2">季</template>-->
<!--          <template v-if="scope.row.procureCircleType==3">月</template>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column align="center" label="采购周期" property="procurePeriodYear"/>-->
<!--      <el-table-column align="center" label="采购周期" property="procurePeriodQuarter"/>-->
      <el-table-column label="申请日期" align="center" width="170">
        <template slot-scope="scope">
          {{ parseTime(scope.row.applyTime) }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="创建人" property="applyUserName" width="120"></el-table-column>
      <el-table-column align="center" label="备注" property="beizhu" :show-overflow-tooltip="true" width="120"></el-table-column>
      <el-table-column label="提交状态" align="center" width="120">
        <template slot-scope="scope">
          <span v-show="scope.row.submitState==1">保存</span>
          <span v-show="scope.row.submitState==2">提交</span>
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" width="120">
        <template slot-scope="scope">
          <span v-show="scope.row.verifyStatus==0">审核中</span>
          <span v-show="scope.row.verifyStatus==1">审核结束</span>
        </template>
      </el-table-column>
      <el-table-column label="当前节点" align="center" width="120">
        <template slot-scope="scope">
          <span v-show="scope.row.verifyIsPass==1">通过</span>
          <span v-show="scope.row.verifyIsPass==2">驳回</span>
          <span v-show="scope.row.verifyIsPass==3">重新申请</span>
          <span v-show="scope.row.verifyIsPass==4">撤销申请</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="审核结果" property="verifyAuditResult" width="120"></el-table-column>
      <el-table-column align="center" label="审核结束日期" property="verifyEndDate" width="170"></el-table-column>

      <!--      <el-table-column align="center" label="当前节点"  property="dqjd" :show-overflow-tooltip="true" ></el-table-column>-->
      <!--      <el-table-column align="center" label="审核状态"  property="verifyStatus" :show-overflow-tooltip="true" width="150" >-->
      <!--        <template slot-scope="scope" style="text-align: center">-->
      <!--          <div style="background:#78BF34  ;color: white;width: 54px;height: 22px;display: inline-block" v-show="scope.row.verifyStatus==1">进行中</div>-->
      <!--          <div style="background:#9E71DC  ;color: white;width: 54px;height: 22px;display: inline-block" v-show="scope.row.verifyStatus==2">已结束</div>-->
      <!--          <div style="background:#DEA11E  ;color: white;width: 54px;height: 22px;display: inline-block" v-show="scope.row.verifyStatus==3">未提交</div>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column align="center" label="审核结束时间" property="verifyEndString"  :show-overflow-tooltip="true" ></el-table-column>-->
      <el-table-column label="操作" align="left" width="260" fixed="right">
        <template slot-scope="scope">
          <el-button v-if="scope.row.submitState==1&&myReview" size="mini" type="primary" icon="el-icon-edit" @click="edit(scope.row)" v-hasPermi="['purchaseGL:cgju:edit']">修改</el-button>
          <el-button v-if="scope.row.submitState==1&&myReview" size="mini" type="danger" icon="el-icon-delete" @click="del(scope.row)" v-hasPermi="['purchaseGL:cgju:delete']">删除</el-button>
          <el-button type="warning" icon="el-icon-download" size="mini" @click="exportInfo(scope.row)">导出</el-button>
          <!-- <el-button size="mini" type="primary" icon="el-icon-edit" @click="pop(scope.row)">操作</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <pagination
      :total="list.total?list.total:0"
      :page.sync="selectForm.pageNum"
      :limit.sync="selectForm.pageSize"
      @pagination="getList"
    />
    <dialog-ap v-if="isDialog" :info="info" @change="closeChange"></dialog-ap>
    <procure-plan-des v-if="isprocureDes" @subSetChane="subSetChane" :pid="pid"></procure-plan-des>
    <procure-plan-add v-if="isprocureAdd" @subSetChane="addSetChane" :pid="aid"></procure-plan-add>
  </div>
</template>
<script>
  import { getToken } from '@/utils/auth'
  import { procurePlan, procurePlanDel ,procurePlanExport,procurePlanList,procurePlanListMe} from '@/api/purchase/index'
  import procurePlanDes from '@/views/components/applicationXQ'
  import procurePlanAdd from './cgjhAdd'
  import request from '@/utils/request'

  import dialogAp from './dialog'

  export default {
    name: 'cgju',
    components:{
      dialogAp,
      procurePlanDes,
      procurePlanAdd
    },
    data() {
      return {
        isDialog:false,
        info:null,

        loading: false,
        list: [],
        selectForm: {
          pageNum: 1,
          pageSize: 10,
          planCode: '',
          applyBeginTime: '',
          applyEndTime: '',
          myReview: 1
        },
        date: '',
        myReview: false,
        headers: { Authorization: 'Bearer ' + getToken() },

        isprocureDes:false,
        pid:null,
        isprocureAdd:false,
        aid:null
      }
    },
    created() {
      this.getList()
      console.log(this.$store.state.user)
    },
    methods: {
      /** 查询设备类型表列表 */
      async getList() {
        this.loading = true
        let res = this.myReview ?await procurePlanListMe(this.selectForm):await procurePlanList(this.selectForm)
        this.list = res
        this.loading = false
      },
      dateSelect() {
        this.selectForm.applyBeginTime = this.date[0]
        this.selectForm.applyEndTime = this.date[1]
      },
      /** 删除*/
      del(row) {
        this.$confirm('确定删除吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(async() => {
          await procurePlanDel(row.id)
          this.$message.success('删除成功')
          this.getList()
        }).catch(() => {
          this.$message.info('取消删除')
        })
      },
      details(row) {
        // this.$router.push({ path: '/purchaseGL/applicationXQ', query: { data: row.id } })
        this.pid=row.id
        this.isprocureDes=true
      },
      subSetChane(){
        this.isprocureDes=false
        this.pid=null
      },
      add() {
        // this.$router.push({ path: '/purchaseGL/cgjhAdd' })
        this.isprocureAdd=true
        this.aid=null
      },
      addSetChane(info){
        this.isprocureAdd=false
        this.aid=null
        if(info) this.getList()
      },
      edit(row) {
        // this.$router.push({ path: '/purchaseGL/cgjhAdd', query: { data: row.id } })
        this.isprocureAdd=true
        this.aid=row.id
      },
      pop(row){
        this.info=row
        this.isDialog=true
      },
      closeChange(){
        this.isDialog=false
      },
      /** 导出按钮操作 */
      exportList() {
        this.$confirm('是否确认导出?', '警告', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(async() => {
          let res = await procurePlanExport(this.selectForm)
          return this.download(res.data)
        }).catch(function() {
        })
      },
      /** 导入**/
      toLeadSuccess(res) {
        if (res.code == 200) {
          this.$message.success('导入成功！')
          this.getList()
        } else {
          this.$message.error(res.msg)
        }
      },
      exportInfo(row){
        //采购计划单个导出
        this.$confirm('是否确认导出?', '警告', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(async() => {
          request({
            url:`/device/procureDevice/excel/${row.id}`,
            method:'get',
          }).then((res)=>{
            this.download(res.data)
          })

        }).catch(function() {
        })

      }
    }
  }
</script>
